package com.ilab.entity;

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

import com.ilab.util.NumberUtils;


public class StaticsInfo implements java.io.Serializable{
	private static final long serialVersionUID = -2639163508596053835L;
	private String sensorName = "";
	private String sensorUnit = "";
	private double maxValue = 0;
	private double minValue = 0;
	private double difference = 0;
	private double avg = 0;
	
	protected List<Double> dataPool = new LinkedList<Double>();
	
	public StaticsInfo(String sensorName,String sensorUnit,double maxValue,double minValue,double difference,double avg){
		this.sensorName = sensorName;
		this.sensorUnit = sensorUnit;
		this.maxValue = maxValue;
		this.minValue = minValue;
		this.difference = difference;
		this.avg = avg;
	}
	
	public StaticsInfo(String sensorName, String sensorUnit){
		this.sensorName = sensorName;
		this.sensorUnit = sensorUnit;
	}

	
	public void addData(Double data){
		dataPool.add(data);
	}
	
	public StaticsInfo statics(){
		if(dataPool.isEmpty()){
			return this;
		}
		Collections.sort(dataPool);
		this.minValue = NumberUtils.round2Double(dataPool.get(0),2);
		this.maxValue = NumberUtils.round2Double(dataPool.get(dataPool.size()-1),2);
		this.difference = NumberUtils.round2Double((maxValue - minValue),2);
		double sum = 0;
		int index = 1;
		for(index = 1;index<=dataPool.size();index++){
			sum += dataPool.get(index-1);
		}
		
		this.avg = NumberUtils.round2Double((sum / dataPool.size()),2);
		return this;
	}
	
	public String getSensorName() {
		return sensorName;
	}

	public void setSensorName(String sensorName) {
		this.sensorName = sensorName;
	}

	public String getSensorUnit() {
		return sensorUnit;
	}

	public void setSensorUnit(String sensorUnit) {
		this.sensorUnit = sensorUnit;
	}

	public double getMaxValue() {
		return maxValue;
	}

	public void setMaxValue(double maxValue) {
		this.maxValue = maxValue;
	}

	public double getMinValue() {
		return minValue;
	}

	public void setMinValue(double minValue) {
		this.minValue = minValue;
	}

	public double getDifference() {
		return difference;
	}

	public void setDifference(double difference) {
		this.difference = difference;
	}

	public double getAvg() {
		return avg;
	}

	public void setAvg(double avg) {
		this.avg = avg;
	}
	
		
}
